#include <unistd.h>

#include "http_parse_task.h"
#include "log.h"
#include "msg.h"
#include "packet_ops.h"
#include "core_data.h"
#include "protocols.h"
#include "sql.h"

extern void PacketProcessing(const unsigned char *packet, unsigned int length);

int http_parse_ops(struct msg *msg)
{
	log_info("begin http_parse_ops.");

	return 0;
}

void *http_parse_loop(void *conf)
{
	log_info("begin http_parse_loop.");

	packet_init();

	sql_init();

	int res;
	res = sql_query("create table TESTB (A float)");
	if (res) {
		log_print("sql_query error: %d, %s", sql_errorno(), sql_error());
	}

	while (1) {
		void *data = get_packet(PROTOCOL_HTTP, NULL);
		if (data == NULL) {
			sleep(1);
			continue;
		}
		unsigned short ipsize = get_ipsize();
		
		PacketProcessing(data, ipsize);	

		free_packet();

		res = sql_query("insert into TESTB values(2.0);");
		if (res) {
			log_print("sql_query error: %d, %s", sql_errorno(), sql_error());
		}

	}
}
